#pragma once

#include <QtWidgets/QMainWindow>
#include <QButtonGroup>
#include <QFile>
#include <QFileDialog>
#include <QCryptographicHash>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
#include "log.h"
#include "const.h"
#include <curl/curl.h>
#include "http_common.h"
#include "ui_ssmsfileassistant.h"
#include "uploaditem.h"
#include "downloaditem.h"

class SSMSFileAssistant : public QMainWindow
{
    Q_OBJECT

public:
    SSMSFileAssistant(QWidget *parent = Q_NULLPTR);
	~SSMSFileAssistant();
	public Q_SLOTS:
	void on_rbUpload_clicked();
	void on_rbDownload_clicked();
	void on_pbUpload_clicked();
	void on_pbDownload_clicked();
	private Q_SLOTS:
	void finishUploadSlot(QString sessionId);
	void pauseUploadSlot(QString sessionId);
	void resumeUploadSlot(QString sessionId);
	void deleteUploadSlot(QString sessionId);
	void updateProgressValueSlot(QString sessionId, int progress);
	void transcodeDownloadSlot(QString sessionId);
	void transcodeFailedDownloadSlot(QString sessionId);
	void finishDownloadSlot(QString sessionId);
	void pauseDownloadSlot(QString sessionId);
	void resumeDownloadSlot(QString sessionId);
	void deleteDownloadSlot(QString sessionId);
private:
	void initDb();
	void loadConfigData();
	void loadUploadData();
	void loadDownloadData();
	QString getSessionId(QString filePath);
	void addUploadItem(QString id, QString filePath, QString status, int progress);
	void addDownloadItem(QString id, QString status);
private:
    Ui::SSMSFileAssistantClass ui;
	QSqlDatabase m_database;
	QSqlQuery m_sqlQuery;
	QString m_fileServerIP;
	QString m_fileServerPort;
	QString m_uploadUrl;
	QMap<QString, UploadItem*> m_uploadMap;
	QString m_downloadUrl;
	QMap<QString, DownloadItem*> m_downloadMap;
};
